package com.le.tester.leetcode;

/**
 * createTime：2025-04-02 16:05
 * description：最长的回文字符串
 */
public class PalindromeLongest {

    public boolean isPalindrome(String s) {
        int length = s.length();
        for (int i = 0; i < length / 2; i++) {
            if (s.charAt(i) != s.charAt(length - i - 1)) {
                return false;
            }
        }
        return true;
    }

    public String longestPalindrome(String s) {
        String result = null;
        int max = 0;
        int length = s.length();
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j <= length; j++) {
                String strIJ = s.substring(i, j);
                if (isPalindrome(strIJ) && strIJ.length() > max) {
                    result = s.substring(i, j);
                    //比较和本身的最大值，从0开始比较
                    max = Math.max(max, result.length());
                }

            }
        }
        return result;

    }

    public static void main(String[] args) {
        PalindromeLongest palindromeLongest = new PalindromeLongest();
        String s = "aacabdkacaa";
        System.out.println(palindromeLongest.longestPalindrome(s));


    }
}
